//
//  HLRtcUserInfoView.m
//  YueYue
//
//  Created by hulu001 on 2023/6/20.
//

#import "HLRtcUserInfoView.h"

@implementation HLRtcUserInfoView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.2];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 12;
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_greaterThanOrEqualTo(172);
        }];
        
        self.avatarView = [UIImageView.alloc init];
        _avatarView.layer.cornerRadius = 12;
        _avatarView.layer.masksToBounds = YES;
        [self addSubview:_avatarView];
        [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(40);
            make.left.top.bottom.mas_equalTo(0);
        }];
        
        self.nameLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(12) textColor:UIColorWhite];
        [self addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_avatarView.mas_right).offset(6);
            make.top.mas_equalTo(4);
        }];
        
        
        self.durationLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(10) textColor:UIColorWhite];
        [self addSubview:_durationLabel];
        [_durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_nameLabel);
            make.bottom.mas_equalTo(-4);
        }];
        
        
        
        self.followButton = [QMUIButton buttonWithType:UIButtonTypeCustom];
        _followButton.layer.cornerRadius = 12;
        _followButton.layer.masksToBounds = YES;
        _followButton.backgroundColor = HLMainColor;
        _followButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium];
        [_followButton setImage:[UIImage imageNamed:@"user_jia"] forState:UIControlStateNormal];
        [_followButton setTitle:@"关注" forState:UIControlStateNormal];
        [_followButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _followButton.spacingBetweenImageAndTitle = 0;
        [self addSubview:_followButton];
        
        [_followButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(48, 24));
            make.right.mas_equalTo(-8);
            make.centerY.mas_equalTo(0);
        }];
        
    }
    return self;
}

- (void)setUserM:(HLUserInfoModel *)userM
{
    _userM = userM;
    
    [_avatarView sd_setImageWithURL:[NSURL URLWithString:userM.avatar] placeholderImage:[HLUIHelper avatarPlaceholder]];
    _nameLabel.text = [userM shortName];
    
    self.followButton.hidden = [self showFollowBtn];
}

- (BOOL)showFollowBtn
{
    NSLog(@"followType = %@", self.userM.followType);
    // 只有男的显示关注按钮
    return ([self.userM.followType isEqualToString:@"0"]);
}

@end
